package com.leinao.tensorboard.controller;

import com.alibaba.fastjson.JSON;
import com.leinao.commons.Response;
import com.leinao.login.dto.LoginResultDto;
import com.leinao.tensorboard.service.TensorboardService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author: huopengfei
 * @Date: 2019/5/21 10:36
 * @Description:
 * @Version 1.0
 */
@RestController
@CrossOrigin
public class TensorboardController {
    private static Logger logger = LoggerFactory.getLogger(TensorboardController.class);

    @Autowired
    private TensorboardService tensorboardService;

    @ApiOperation(value = "创建 容器", notes = "创建容器")
    @PostMapping(value = "/tensor/createContainer")
    public Response<String> createContainer(HttpServletRequest request,
                                            //@ApiParam(value = "容器IP", required = true) @RequestParam String ip,
                                            //@ApiParam(value = "容器端口", required = true) @RequestParam String port,
                                            // @ApiParam(value = "容器ID", required = true) @RequestParam String conId,
                                            @ApiParam(value = "任务ID", required = true) @RequestParam Long jobId) {

        logger.info("createContainer param  jobId: {}", jobId);
        String obj = (String) request.getSession().getAttribute("userInfo");
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        Response<String> container = tensorboardService.createContainer(userInfo.getUserId(),jobId);
        return container;
    }
    @ApiOperation(value = "删除容器", notes = "删除容器")
    @GetMapping(value = "/tensor/deleteContainer")
    public Response<List<Object>> deleteContainer(HttpServletRequest request,
                                                  @ApiParam(value = "容器IP", required = true) @RequestParam String ip,
                                                  @ApiParam(value = "容器端口", required = true) @RequestParam String port,
                                                  @ApiParam(value = "容器ID", required = true) @RequestParam String conId,
                                                  @ApiParam(value = "任务ID", required = true) @RequestParam Integer jobId) {

        logger.info("deleteContainer param  jobId: {}", jobId);
        String obj = (String) request.getSession().getAttribute("userInfo");
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        return null;
    }
    @ApiOperation(value = "任务看板", notes = "任务看板")
    @GetMapping(value = "/tensor/jobTensor")
    public Response<List<Object>> jobTensor(HttpServletRequest request,
                                            @ApiParam(value = "容器ID", required = true) @RequestParam String jobId) {

        logger.info("deleteContainer param  jobId: {}", jobId);
        String obj = (String) request.getSession().getAttribute("userInfo");
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        return null;
    }
}
